package com.base.service.business;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import com.base.mapper.prorder.PROrderHeadDataMapper;
import com.base.mapper.prorder.PROrderProductDataItemMapper;
import com.base.mapper.prorder.PROrderRowDataMapper;
import com.base.model.prorder.PROrderDto;
import com.base.model.prorder.PROrderProductDataItem;
import com.base.model.prorder.PROrderRowDataItem;

/**
 * PR单业务处理 放到同一个事物
 * @ClassName: PROrderDataBusiness
 * @Description: 
 * @Author xuyou
 * @DateTime 2019年11月21日 下午4:51:01
 */
@Service
public class PROrderDataBusiness {

	@Autowired
	private PROrderHeadDataMapper pROrderHeadDataMapper;
	@Autowired
	private PROrderRowDataMapper pROrderRowDataMapper;
	@Autowired
	private PROrderProductDataItemMapper pROrderProductDataItemMapper;
	
	
	@Transactional(propagation = Propagation.REQUIRES_NEW)
	public void save(PROrderDto dto) {
		pROrderHeadDataMapper.insert(dto.getHeadData());
		List<PROrderRowDataItem> rowData = dto.getRowData();
		if (!CollectionUtils.isEmpty(rowData)) {
			for (PROrderRowDataItem prOrderRowDataItem : rowData) {
				pROrderRowDataMapper.insert(prOrderRowDataItem);
			}
		}
		List<PROrderProductDataItem> productData = dto.getProductData();
		if (!CollectionUtils.isEmpty(productData)) {
			for (PROrderProductDataItem prOrderProductDataItem : productData) {
				pROrderProductDataItemMapper.insert(prOrderProductDataItem);
			}
		}
	}
	
}
